# 数据库连接
import pymysql as sql

# mysql信息
class Mysql:
    host = "localhost"
    user = "root"
    password = "123456"
    port = 3306
    db = 'learn'

# 连接mysql，并处理可能得错误
try:
    db = sql.connect(
        host=Mysql.host, user=Mysql.user, password=Mysql.password, port=Mysql.port,db= Mysql.db
    )
    print("连接成功")
except:
    print(" 出错了")


cursor = db.cursor()
sql = '''select * from  account '''
sql1 = '''insert into account(name,money) values('苏健尧',6000)'''
cursor.execute(sql1)

# 处理，提交mysql信息
db.commit()
res = cursor.fetchall()
for row in res:
    print(row)
    
# 关闭数据库
db.close()